<template>
  <div>
    <div class="goods-list">
      <router-link tag="div" :to="'/home/goodsInfo/'+item.id" class="goods-item" v-for="(item,i) in goodlist" :key="i">
        <img src="../../images/iPhone12.jpg" alt="" />
        <h1 class="title">{{item.title}}</h1>
        <div class="info">
          <p class="price">
            <span class="new">￥{{item.sell_price}}</span>
            <span class="old">￥{{item.market_price}}</span>
          </p>
          <p class="sell">
            <span class="new">热卖中</span>
            <span class="old">{{item.stock_quantity}}</span>
          </p>
        </div>
      </router-link>
    
    </div>
    <mt-button type="danger" size="large" style="margin-top:10px" @click="getmore">加载更多 </mt-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      page:0,
      goodlist:[],
      isloaded:false,
    };
  },
  methods: {
    getGoodsListByPage() {
        this.$http.get('/api/getgoods?pageindex='+this.page).then(result=>{
            console.log(this.isloaded)
            if(result.data.message.length<=0){this.isloaded=true;}
            
            this.goodlist=this.goodlist.concat(result.data.message)
        })
    },
    getmore(){
        console.log(this.isloaded)
        if(this.isloaded) return ;
        this.page++
        this.getGoodsListByPage()
    }
  },
  created(){
      this.getGoodsListByPage()
  },
//   props:["id"]
};
</script>
<style lang="scss" scoped>
.goods-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 7px;
}
.goods-item {
  padding: 2px;
  width: 49%;
  border: 1px solid #ccc;
  margin-bottom: 7px;
  box-shadow: 0 0 7px #ccc;
  //贴边
  flex-direction: column;
  justify-content: space-between;
  display: flex;
}
img {
  width: 100%;
  min-height: 170px;
}
.title {
  font-size: 14px;
}
.info {
  background-color: #eee;
  overflow: hidden;
  p{
        margin: 3px;
    }
  .price {
    .new {
      font-size: 16px;
      font-weight: bold;
      color: red;
      margin-right: 15px;
    }
  }
  .sell {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    
  }
}
</style>